<?php

namespace app\admin\model\admin;



use app\common\Constants;
use think\facade\Log;

class Dict extends BaseDict
{


    // 读取器：仅当 type == 1 时才 json_decode
    public function getSqlAttr($value,$data)
    {
        if($data['type'] === Constants::DICT_TYPE_GENERAL){
            return json_decode($value, true);
        }
        return $value;
    }

    // 修改器：仅当 type == 1 且值为数组时才 json_encode
    public function setSqlAttr($value,$data)
    {
        if ($data['type'] === Constants::DICT_TYPE_GENERAL && is_array($value)) {
            return json_encode($value, JSON_UNESCAPED_UNICODE);
        }
        return $value;
    }

}